package com.example.verification.service.impl;

import com.example.verification.mapper.UserMapper;
import com.example.verification.model.User;
import com.example.verification.service.UserService;
import com.example.verification.utils.SysTools;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author rcl
 * @date 2019/7/29 10:09
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String saveUser(User user) {
        user.setId(SysTools.getUUID());
        user.setPassword(SysTools.getPassword(user.getName()));
        SysTools.setCreatedTime(user, null);
        userMapper.saveUser(user);
        return user.getId();
    }

    @Override
    public User findByName(String name) {
        // 查询用户是否存在
        User bean = userMapper.findByName(name);
        if (bean != null) {
            // 查询用户信息、角色、权限
            bean = userMapper.findById(bean.getId());
        }
        return bean;
    }

    @Override
    public List<User> getList() {
        return userMapper.getUsers();
    }

    @Override
    public Page<User> getUserList(Map map) {
        return userMapper.getUserList(map);
    }
}
